package ar.edu.caece.compiler.grammar.factories;

import ar.edu.caece.compiler.error.ErrorManager;
import ar.edu.caece.compiler.error.ParsingException;
import ar.edu.caece.compiler.grammar.AbstractTokenVisitorFactory;
import ar.edu.caece.compiler.grammar.Recognizer;
import ar.edu.caece.compiler.grammar.TokenRecognizer;
import ar.edu.caece.compiler.grammar.TokenVisitor;
import ar.edu.caece.compiler.grammar.attributes.Attribute;

import ar.edu.caece.compiler.grammar.attributes.StringAttribute;
import ar.edu.caece.compiler.grammar.nonterminals.OP23;
import ar.edu.caece.compiler.grammar.terminals.DivisionEnteroToken;

public class OP23Factory extends AbstractTokenVisitorFactory {

	private static OP23Factory INSTANCE;
	
	public static OP23Factory getInstance() {
		if(INSTANCE==null) INSTANCE = new OP23Factory();
		return INSTANCE;
	}
	
	private OP23Factory() {
		
	}
	
	@Override
	public TokenVisitor makeChainedVisitor(
			final TokenVisitor siguiente) throws Exception {
		return new DivisionEnteroToken.DivisionEnteroChainVisitor(siguiente) {
			
			@Override
			public Recognizer divisionEnteroCase(DivisionEnteroToken llamador) {
				OP23 op23 = new OP23(llamador);
				op23.addAttribute("tipo", new StringAttribute("ENTERO"));
				op23.addAttribute(Attribute.OPERACION, new StringAttribute("DIVISION"));

				return op23;
			}
		};
	
	}
	@Override
	public TokenVisitor makeVisitor() throws Exception {
		return new DivisionEnteroToken.DivisionEnteroTokenVisitor() {
			
			@Override
			public Recognizer defaultCase(TokenRecognizer llamador) throws Exception {
				ErrorManager.getInstance().manage(llamador,"OP23",new ParsingException("Error de parsing.",OP23.class,llamador));
				return null;
			}
			
			@Override
			public Recognizer divisionEnteroCase(DivisionEnteroToken llamador) {
				OP23 op23 = new OP23(llamador);
				op23.addAttribute("tipo", new StringAttribute("ENTERO"));
				op23.addAttribute(Attribute.OPERACION, new StringAttribute("DIVISION"));

				return op23;
			}
		};
	}
	
	
}
